package thread;

/**
 * Created with IntelliJ IDEA.
 * Description: 定义匿名内部类，Runnable子类
 * User: 王圆豪
 * Date: 2025-04-22
 * Time: 20:30
 */
public class Demo4 {
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                while (true){
                    System.out.println("Hello Thread!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };
        Thread t = new Thread(runnable);
        t.start();
        while (true){
            System.out.println("Hello main!");
            Thread.sleep(1000);
        }
    }
}
